/**
 * 分销商管理
 *
 * Created on 2018/2/6
 *
 * @author xiaofeng
 */
import {queryDistributorManage, updateDistributorManage,updateDistributorShopInfo} from '../services/distributorApi';

export default{
    namespace: 'distributorManage',
    state:{
        submitting:false,
        data:{
            list:[],
            pagination:{},
        },
    },

    effects: {

        *queryAll({payload, callback}, {put, call}){
            yield put({
                type: 'changeLoading',
                payload: true,
            })
            const response = yield call(queryDistributorManage, payload);
            yield put({
                type: 'handleResponse',
                payload: response,
            })
            yield put({
                type: 'changeLoading',
                payload: false,
            })
        },

        *updateDistributor({payload, callback}, {put, call}){
            const response = yield call(updateDistributorManage, payload);
            if (callback) callback(response);
        },
        *updateShopInfo({payload, callback}, {put, call}){
          const response = yield call(updateDistributorShopInfo, payload);
          if (callback) callback(response);
        },
    },

    reducers: {
        changeLoading(state,{payload}){
            return ({
                ...state,
                submitting:payload,
            })
        },
        handleResponse(state,{payload}){
            return ({
                ...state,
                data:payload.resultData.distributorManage,
            })
        },
    }

}